import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import '../../constant/constant.dart';
import '../../entity/videocategory.dart';

class VideoPage extends StatefulWidget {
  const VideoPage({super.key});

  @override
  State<StatefulWidget> createState() => _VideoPageState();

  // @override
  // _VideoPageState createState() => _VideoPageState();
}

class _VideoPageState extends State<VideoPage> with TickerProviderStateMixin {
  TabController? mTabController;
  List<VedioCategory> mTabList = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    mTabList.add(VedioCategory(id: 1, cname: "推荐"));
    mTabList.add(VedioCategory(id: 2, cname: "热门"));
    mTabList.add(VedioCategory(id: 3, cname: "小视频"));
    mTabController = TabController(length: mTabList.length, vsync: this);
    // DioManager.instance.post(ServiceUrl.getVedioCategory, null, (data) {
    //   List<VedioCategory> mList = VedioCategoryList.fromJson(data).data;
    //   setState(() {
    //     mTabList = mList;
    //     mTabController = TabController(length: mTabList.length, vsync: this);
    //   });
    // }, (error) {
    //   //ToastUtil.show(error);
    // });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        //color: MyColorRes.bgTagColor,
        child: Column(
          children: <Widget>[
            Container(
              alignment: Alignment.center,
              height: 50,
              child: TabBar(
                isScrollable: true,
                indicatorColor: Colors.transparent,
                labelColor: Color(0xffF78005),
                unselectedLabelColor: Color(0xff666666),
                labelStyle: TextStyle(
                  fontSize: 17.0,
                  fontWeight: FontWeight.w700,
                ),
                unselectedLabelStyle: TextStyle(fontSize: 16.0),
                indicatorSize: TabBarIndicatorSize.label,
                controller: mTabController,
                tabs:
                    mTabList.map((value) {
                      return Text(value.cname);
                    }).toList(),
              ),
            ),
            Container(
              child: Center(
                child: Container(
                  width: MediaQuery.of(context).size.width,
                  margin: EdgeInsets.only(left: 10, right: 10),
                  padding: EdgeInsets.only(top: 8, bottom: 8),
                  decoration: BoxDecoration(
                    color: Color(0xffE4E2E8),
                    borderRadius: BorderRadius.all(
                      //圆角
                      Radius.circular(5.0),
                    ),
                  ),
                  child: Center(
                    child: Container(
                      child: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.only(right: 5, top: 2),
                            child: Image.asset(
                              '${Constant.ASSETS_IMG}find_top_search.png',
                              width: 12.0,
                              height: 15.0,
                            ),
                          ),
                          Text(
                            "搜你想看的视频",
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(
                              fontSize: 14,
                              color: Color(0xffee565656),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              flex: 1,
              child: TabBarView(
                controller: mTabController,
                children: <Widget>[
                  VideoRecommendPage(),
                  VideoHotPage(),
                  VideoSmallVideoPage(),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(
      DiagnosticsProperty<TabController>('mTabController', mTabController),
    );
  }
}

class VideoRecommendPage extends StatelessWidget {
  const VideoRecommendPage({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(body: Container(color: Color(0xff999999)));
  }
}

class VideoHotPage extends StatelessWidget {
  const VideoHotPage({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(body: Container(color: Color(0xff00ffff)));
  }
}

class VideoSmallVideoPage extends StatelessWidget {
  const VideoSmallVideoPage({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(body: Container(color: Color(0xff00ff00)));
  }
}
